package com.umiwe.permission.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import com.umiwe.entity.UmiweUserDepartment;
import org.apache.ibatis.annotations.*;

import java.util.ArrayList;

@Mapper
public interface UserDepartmentMapper extends BaseMapper<UmiweUserDepartment> {

    //添加部门
    @Insert("INSERT INTO umiwe_department(id, department_name,is_delete,create_time,parent_id) VALUES (#{umiweUserDepartment.id}, #{umiweUserDepartment.departmentName}," +
            " #{umiweUserDepartment.isDelete},NOW(),#{umiweUserDepartment.parentId})")
   boolean addDepartment(@Param("umiweUserDepartment")UmiweUserDepartment umiweUserDepartment);

    /**
     * 修改操作
     */
    @Select("select EXISTS(SELECT 1 FROM umiwe_department WHERE id=#{id})")
    boolean getDepartmentId(@Param("id")Integer id);


    @Update("UPDATE umiwe_department SET department_name = #{umiweUserDepartment.departmentName},"
            +"update_time = NOW(),parent_id = #{umiweUserDepartment.parentId}"
            +" WHERE id = #{umiweUserDepartment.id}")
    boolean updateData(@Param("umiweUserDepartment")UmiweUserDepartment umiweUserDepartment);

    /**
     * 查询3分钟之前的数据
     */
    @Select("SELECT id FROM umiwe_department t WHERE  t.update_time<= CONCAT(date_format(DATE_SUB(NOW(), INTERVAL 3 MINUTE),'%Y%m%d%H%i%S'))")
    ArrayList<Long> dateDepartmentList();

    /**
     * 修改部门 状态
     */

    @Update("update umiwe_department set is_delete = 2 where id = #{id}")
    boolean updateDelete(@Param("id")Long id);
}
